﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace RecruitmentProcessSystem
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            try
            {
                if (txtName.Text == "" || txtPass.Text == "")
                {
                    MessageBox.Show("Bạn chưa điền đầy đủ thông tin", "Có lỗi xảy ra!");
                    txtName.Focus();
                    return;
                }
                else
                {
                    ConnectData connect = new ConnectData();
                    //connect.connect();
                    String conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
                    SqlConnection con = new SqlConnection(conStr);
                    con.Open();
                    SqlCommand cmd = new SqlCommand("Select * from Nhanvien where tendn ='" + txtName.Text + "'", con);
                    SqlDataReader reader = cmd.ExecuteReader();
                    reader.Read();
                    if (txtPass.Text == reader.GetValue(3).ToString())
                    {
                        
                        String name = reader.GetValue(1).ToString();
                        String user = reader.GetValue(2).ToString();
                        String role = reader.GetValue(6).ToString();
                        MessageBox.Show("Chào mừng "+name+" đã đăng nhập thành công!", "Thành công");
                        reader.Close();
                        con.Close();
                        this.Hide();
                        frmMainRibbon frm = new frmMainRibbon();
                        frm.Show();                        
                    }
                    else
                    {
                        MessageBox.Show("Sai Mật Khẩu");
                        txtPass.Focus();
                    }
                    reader.Close();
                    con.Close();
                }

            }
            catch (Exception loi)
            {

                MessageBox.Show("Loi :"+loi.ToString(), "Có lỗi xảy ra");
                txtName.Focus();

            }  
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }
    }
}
